﻿//click to log in button in form
$j(document).ready(function () {
    $j("#fbtnLogin").click(function () {
        $j.get("/Ajax/Login.aspx?id=" + $j("#fUn").val() + "&pw=" + $j("#fPw").val(), function (response) {
            if ((response == "Username is not exist") || (response == "Password incorrect")) {
                alert(response);
                return false;
            }
            else {                
                var res = response.toString();
               // alert(res);
              //  var spl = res.split(":");
                $j('#formLogIn').fadeOut();
                $j('#manage').fadeIn(500);
                $j('a#btnLogIn').html("Sign Out");

                if ($j('#fUn').val() == "Admin") {
                    //alert("A");
                    $j('#tomanage').attr("href", "/Admin/ManageUsers.aspx");
                } else {
                    $j('#tomanage').attr("href", "/Users/ManageItems.aspx");
                }
                //alert($j('#fUn').val() + "A");                
                $j('#toinfo').html($j('#fUn').val());
            }
        });//end response function     
    });//end get function
}); //end click form button

//click to log in button in top
$j(document).ready(function () {
    $j('#btnLogIn').click(function () {
        //$j("#formLogIn").css("display", "block");        
        if ($j('a#btnLogIn').html() != "Sign Out") {                    
            $j('#formLogIn').fadeToggle(1000);
        }
        else {
            //sign out
            $j('#formLogIn').fadeOut();
            $j('#manage').fadeOut();
            $j('a#btnLogIn').html("Sign In");
            $.get("../Ajax/Logout.aspx");
            $("#fUn").val("");
            $("#fPw").val("");         
            alert('You have been signed out');
            location.replace("../Home.aspx");
        }
    });
});
//click to link manage
$j(document).ready(function () {
    $j("#tomanage").click(function () {
        $j('#formLogIn').fadeOut();
        $j('#manage').fadeIn(500);
        $j('a#btnLogIn').html("Sign Out");
    });
});